package com.summer.peony.myinterface.controller;

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.summer.peony.common.entity.AjaxResult;
import com.summer.peony.myinterface.pojo.MyInterface;
import com.summer.peony.myinterface.service.TestBaseService;
import com.sun.el.parser.ParseException;

@RestController
@RequestMapping("/testBase")
public class TestBaseController {

	@Autowired
	private TestBaseService testBaseService;

	/**
	 * @Description: TODO(执行接口测试)
	 * @param myInterface
	 * @return AjaxResult
	 * @author: TaoGe
	 * @throws ParseException
	 * @date: 2020年12月21日 上午10:06:20
	 * @throws:
	 */
	@PostMapping("/executeTest")
	public AjaxResult executeTest(@RequestBody MyInterface myInterface) throws ParseException {
		AjaxResult ajaxResult = new AjaxResult();
		Integer myInf = null;
		try {
			myInf = testBaseService.executeTest(myInterface);
			if (myInf == 200) {
				ajaxResult.put("code", 0);
				ajaxResult.put("msg", "执行成功");
				return ajaxResult;
			} else if (myInf == 0) {
				ajaxResult.put("code", 999999);
				ajaxResult.put("msg", "请求方法未启用，敬请期待");
				return ajaxResult;
			} else if (myInf == 2) {
				ajaxResult.put("code", 999999);
				ajaxResult.put("msg", "添加执行结果出错");
				return ajaxResult;
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		ajaxResult.put("code", 999999);
		ajaxResult.put("msg", "返回状态码" + myInf);
		return ajaxResult;
	}
}
